﻿using LPP.Entity.Notification;
using LPP.Service.NotificationService;
using Microsoft.AspNetCore.Mvc;

namespace LPP.API.Controllers.NotificationController;
       [Route("api/[controller]")]
       [ApiController]
public class NotificationController : ControllerBase
{
    private readonly INotificationService _notificationService;

    public NotificationController(INotificationService notificationService)
    {
        _notificationService = notificationService;
    }

    [HttpPost]
    public async Task<IActionResult> CreateNotification([FromBody] Notification notification)
    {
        var result = await _notificationService.CreateNotificationAsync(notification);
        if (result) return Ok();
        return BadRequest();
    }

    [HttpGet("{id}")]
    public async Task<IActionResult> GetNotificationById(int id)
    {
        var notification = await _notificationService.GetNotificationByIdAsync(id);
        if (notification != null) return Ok(notification);
        return NotFound();
    }

    [HttpGet]
    public async Task<IActionResult> GetAllNotifications()
    {
        var notifications = await _notificationService.GetAllNotificationsAsync();
        return Ok(notifications);
    }

    [HttpPut]
    public async Task<IActionResult> UpdateNotification([FromBody] Notification notification)
    {
        var result = await _notificationService.UpdateNotificationAsync(notification);
        if (result) return Ok();
        return BadRequest();
    }

    [HttpDelete("{id}")]
    public async Task<IActionResult> DeleteNotification(int id)
    {
        var result = await _notificationService.DeleteNotificationAsync(id);
        if (result) return Ok();
        return NotFound();
    }
}
    

